<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>蜂来采蜜超市(系统管理平台)</title>
<#include "../common/header.ftl"/>
    <link type="text/css" rel="stylesheet" href="/plugins/uploadifive/uploadifive.css"/>
    <script type="text/javascript" src="/plugins/uploadifive/jquery.uploadifive.min.js"></script>
    <script type="text/javascript" src="/js/jquery/jquery.form.js"></script>
    <script type="text/javascript" src="/js/jquery.twbsPagination.min.js"></script>

    <script type="text/javascript">
        $(function () {
            $('#pagination').twbsPagination({
                        totalPages: ${pageResult.pages} || 1,
                    startPage: ${qo.currentPage},
            visiblePages : 5,
                    first:"首页",
                    prev:"上一页",
                    next:"下一页",
                    last:"最后一页",
                    onPageClick
            :
            function (event, page) {
                $("#currentPage").val(page);
                $("#searchForm").submit();
            }
        })
            ;
            //点击编辑
            $(".updateClass").click(function () {
                var json = $(this).data("json");
                $("#id").val(json.id);
                $("#sort").val(json.sort);
                $("#image").val(json.image);
                $("#state").val(json.state);
                $("[name=state] option[value="+json.state+"]").attr("selected", "selected");
                $("#name").val(json.name);
                $("#price").val(json.price);
                $("#imageShow").prop("src", json.image);
                $("#myModal").modal("show");
            });

            //点击新增
            $("#addCommodity").click(function () {
                $("#id").val('');
                $("#image").val('');
                $("#state").val('');
                $("#name").val('');
                $("#price").val('');
                $("#imageShow").prop("src", '');
                $("#myModal").modal("show");
            });

            //确定
            $(".btn_confirm").click(function () {
                $("#editform").ajaxSubmit({
                    dataType: 'json',
                    success: function (data) {
                        if (data.result) {
                            window.location.reload();
                        } else {
                            $.messager.popup(data.message);
                        }
                    }
                });
            });

            //点击查询
            $("#query").click(function () {
                $("#currentPage").val(1);
                $("#searchForm").submit();
            })

            //点击上传图片
            $("#uploadBtn").uploadifive({
                buttonText: '上传图片',//按钮文本
                fileObjName: 'pic',//表单提交的时候的名字
                uploadScript: '/uploadImg',//提交路径
                multi: false,//是否多选
                onInit: function () {
                    //在上传初始化的时候把上传的进度条隐藏
                    $("#uploadifive-uploadBtn1-queue").hide();
                },
                onUploadComplete: function (file, data) {
                    //上传完毕后回显
                    $("#imageShow").prop("src", data);
                    $("#image").val(data);
                }
            });
        });
    </script>
</head>
<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
        <#assign currentMenu="commodity" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>日用品管理</h3>
            </div>
            <div>
                <form id="searchForm" class="form-inline" method="post" action="/commodity_list">
                    <input type="hidden" id="currentPage" name="currentPage" value=""/>
                    <div class="form-group">
                        <label>状态</label>
                        <select class="form-control" name="state">
                            <option value="-1">全部</option>
                            <option value="0">上架</option>
                            <option value="1">下架</option>
                        </select>
                        <script type="text/javascript">
                            $("[name=state] option[value='${(qo.state)!''}']").attr("selected", "selected");
                        </script>
                        <input class="form-control" name="keyword" value="${(qo.keyword)!''}">
                    </div>
                    <div class="form-group">
                        <button id="query" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                </form>
                <a href="javascript:void(-1);" class="btn btn-success"
                   id="addCommodity">新增</a>
            </div>
        </div>
        <div class="panel panel-default">
            <table class="table" align="center">
                <thead>
                <tr>
                    <th>日用品图片</th>
                    <th>日用品名称</th>
                    <th>日用品价格</th>
                    <th>日用品状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <#list pageResult.list as info>
                <tr>
                    <td><img src="${info.image}" style="width: 30px;height: 30px;"/></td>
                    <td>${info.name}</td>
                    <td>${info.price}</td>
                    <td><#if (info.state == 0)>上架<#else >下架</#if></td>
                    <td>
                        <a href="javascript:void(-1);" class="updateClass" data-json='${info.json}'>编辑</a>
                        <a href="javascript:void(-1);" class="deleteClass" data-json='${info.json}'>删除</a>
                    </td>
                </tr>
                </#list>
                </tbody>
            </table>
            <div style="text-align: center;">
                <ul id="pagination" class="pagination"></ul>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <form class="form-horizontal" id="editform" method="post" action="/saveOrUpdate">
                    <fieldset>
                        <div id="legend" class="">
                            <legend>日用品操作</legend>
                        </div>
                        <input type="hidden" name="id" id="id" value=""/>
                        <input type="hidden" name="sort" id="sort" value="2"/>
                        <input type="hidden" name="image" id="image" value=""/>
                        <div class="row">
                            <label class="col-sm-2 control-label" for="name">日用品名称</label>
                            <div class="col-sm-4">
                                <input class="form-control" name="name" id="name">
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-2 control-label" for="name">日用品价格</label>
                            <div class="col-sm-4">
                                <input class="form-control" name="price" id="price">
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-2 control-label" for="name">日用品状态</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="state">
                                    <option value="0">上架</option>
                                    <option value="1">下架</option>
                                </select>
                            </div>
                        </div>
                        <br/>
                        <div class="row">
                            <label class="col-sm-2 control-label" for="name">日用品图片</label>
                            <div class="col-sm-4">
                                <img src="" id="imageShow" style="width: 150px;height: 150px;"/>
                                <a href="javascript:;" id="uploadBtn" class="btn btn-success"></a>
                            </div>
                        </div>
                    </fieldset>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-success btn_confirm" value="1">确定</button>
            </div>
        </div>
    </div>
</div>
</div>
</body>
</html>